--  loginnode操作：(验证uid, 根据uid去查询rid， rid不存在，从set中获取一个随机rid，然后再去写uid <-> rid 对应关系）

local skynet = require "skynet"
require "skynet.manager"
local cluster = require "skynet.cluster"

local filelog = require "filelog"
local tabletool = require "tabletool"
local configdao = require "configdao"

skynet.start(function()
	skynet.newservice("nodelog")
	local confsharesvr = skynet.newservice("confshare")
	skynet.call(confsharesvr, "lua", "start")

	--加载pbcservice
	-- 手工来添加需要的解析文件，更加严谨一些，不要做成自动添加的
	-- 最后在使用的service里面，再调用
	-- debug.getregistry().PROTOBUF_ENV = skynet.call(".pbcservice", "lua", "get_protobuf_env")
	-- self.protobuf = require "protobuf"
	-- self.decode = require "protopack"

	local pbcservice = skynet.uniqueservice("pbcservice")
	local protofilename = {"primary"}
	skynet.call(pbcservice, "lua", "init", "../", protofilename)

	local loginnode = configdao.get_cfgsvrs_key("loginnode")
	skynet.newservice("debug_console",loginnode.debug_console_port)

	skynet.name(".gamedatalog", skynet.newservice("datalog"))    -- 游戏数据日志处
	skynet.call(".gamedatalog", "lua", "init", "gamedata")       -- applog/gamegate检查目录是否存在

	-- 需要连接到gm的redis， 主要是为了给后台push消息
	skynet.name(".gmmqredis", skynet.newservice("redisdb"))	
	skynet.call(".gmmqredis", "lua", "init", configdao.get_cfgsvrs_key("gmmqredis"))

	skynet.name(".router", skynet.uniqueservice("router") )	

	skynet.newservice("webserver")

	cluster.open("loginnode")
	local watchdog = skynet.newservice("loginnode")

	skynet.call(watchdog, "lua", "cmd", "start", {
		port = loginnode.svr_port,
		maxclient = loginnode.maxclient or 10000,
		nodelay = true,
		agentsize = loginnode.agentsize or 500,
		agentincr = loginnode.agentincr or 100,
	})
    skynet.name(".mainnode", watchdog)
	skynet.exit()
end)
